package com.wnxy.carl.exception;

import com.wnxy.carl.response.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class TotalException {


    @ExceptionHandler(DemoRuntimeException.class)
    public Result eemoRuntimeException(DemoRuntimeException e){
        log.warn("运行时异常：{}",e.getMessage());
//        System.out.println("!!!!!!!!!运行时异常："+e.getMessage());
        if (null != e.getCode()){
            Boolean bool = false;
            if ("2002".equals(e.getCode())){
                bool = true;
            }
            return Result.runFail(bool,e.getCode(),e.getMessage());
        }
        return Result.runFail(e.getMessage());
    }
    @ExceptionHandler(CheckRuntimeException.class)
    public Result checkRuntimeException(CheckRuntimeException e){
        log.warn("参数验证异常：{}",e.getMessage());
//        System.out.println("!!!!!!!!!参数验证异常："+e.getMessage());
        return Result.checkFail(e.getMessage());
    }
    @ExceptionHandler(Exception.class)
    public Result exception(Exception e){
        log.error("发送未知系统异常：{}",e);
//        System.out.println("!!!!!!!!!发送未知系统异常："+e.getMessage());
        return Result.fail("5005","发送未知系统异常");
    }
}